<?php

/**
 * This is the model class for table "{{objects}}".
 *
 * The followings are the available columns in table '{{objects}}':
 * @property integer $object_id
 * @property string $name
 * @property string $description
 * @property string $cdate
 * @property integer $org_id
 * @property integer $type
 * @property integer $qvo_id
 * @property integer $s_zyklus
 * @property integer $s_zyklus_gap
 * @property integer $s_zyklus_start
 * @property string $s_zyklus_time
 * @property string $s_format
 *
 * The followings are the available model relations:
 * @property Objectlink[] $objectlinks
 * @property Qvobjects $qvo
 * @property Weekdays[] $tblWeekdays
 */
class Objects extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Objects the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{objects}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('org_id, type, qvo_id, s_zyklus, s_zyklus_gap, s_zyklus_start,type', 'numerical', 'integerOnly'=>true),
			array('name', 'length', 'max'=>100),
			array('s_format', 'length', 'max'=>45),
			array('description, cdate, s_zyklus_time', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('object_id, name, description, cdate, org_id, type, qvo_id, s_zyklus, s_zyklus_gap, s_zyklus_start, s_zyklus_time, s_format', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'objectlinks' => array(self::HAS_MANY, 'Objectlink', 'object_id'),
			'qvo' => array(self::BELONGS_TO, 'Qvobjects', 'qvo_id'),
			'tblWeekdays' => array(self::MANY_MANY, 'Weekdays', '{{weekdays_has_tbl_objects}}(tbl_objects_object_id, tbl_weekdays_weekday_id)'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'object_id' => 'Object',
			'name' => 'Name',
			'description' => 'Description',
			'cdate' => 'Cdate',
			'org_id' => 'Responsible',
			'type' => 'Type',
			'qvo_id' => 'QlikView Object',
			's_zyklus' => 'Zyklus',
			's_zyklus_gap' => 'Zyklus Gap',
			's_zyklus_start' => 'Zyklus Start',
			's_zyklus_time' => 'Zyklus Time',
			's_format' => 'Format',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('object_id',$this->object_id);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('description',$this->description,true);
		$criteria->compare('cdate',$this->cdate,true);
		$criteria->compare('org_id',$this->org_id);
		$criteria->compare('type',$this->type);
		$criteria->compare('qvo_id',$this->qvo_id);
		$criteria->compare('s_zyklus',$this->s_zyklus);
		$criteria->compare('s_zyklus_gap',$this->s_zyklus_gap);
		$criteria->compare('s_zyklus_start',$this->s_zyklus_start);
		$criteria->compare('s_zyklus_time',$this->s_zyklus_time,true);
		$criteria->compare('s_format',$this->s_format,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}